package org.fjsei.yewu.config;

import org.apache.http.impl.client.DefaultRedirectStrategy;
import org.springframework.data.annotation.Immutable;

/*
只有服务器返回header location不为空，且DefaultRedirectStrategy只支持GET、HEAD客户端跳转，不支持POST
* */
@Immutable
public class CustomRedirectStrategy extends DefaultRedirectStrategy {
    private static final String[] REDIRECT_METHODS = new String[]{"GET", "POST", "HEAD"};


    protected boolean isRedirectable(String method) {
        String[] arr$ = REDIRECT_METHODS;
        int len$ = arr$.length;

        for (String m : arr$) {
            if (m.equalsIgnoreCase(method)) {
                return true;
            }
        }

        return false;
    }
//
//    @Override
//    public URI getLocationURI(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
//        Header location = response.getFirstHeader("location");
//        if(location != null && location.getValue().contains("xxx")){
//            List<String> cookieList = new ArrayList<>();
//
//            String xxx = request.getFirstHeader("Upgrade-Insecure-Request").getValue();
//            for(Header header: response.getHeaders(HttpHeaders.SET_COOKIE)){
//                cookieList.add(header.getName() + "=" + header.getValue());
//            }
//        /*ThreadContextUtil.put("NEW_FORWARD_URL",location.getValue());
//        ThreadContextUtil.put("COOKIE_LIST",cookieList);*/
//            if(Constants.xxx.size() > 1000)
//                Constants.xx.clear();
//            if(Constants.xxx.size() > 1000)
//                Constants.xxx.clear();
//
//            Constants.xxx.put(xxx,location.getValue());
//            Constants.xx.put(xx,cookieList);
//        }
//
//        return super.getLocationURI(request, response, context);
//    }

}

